{include file="public/header"}
<body>
<div class="layui-fluid">
    <div class=" layui-card">
        <div class="layui-card-body">
            <div class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin"
                 style="padding: 20px;">
                <div class="layui-form-item">
                    <label class="layui-form-label">文件名称</label>
                    <div class="layui-input-block">
                        <div class="layui-form-mid" id="fileName"></div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">html代码</label>
                    <div class="layui-input-block">
                    <div id="html" style="width: 100%; height: 500px;"></div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-normal" ht-event="save">保存</button>
                        <button class="layui-btn layui-btn-primary" ht-event="back">返回</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/common"}
<script src="/static/ace/ace.js"></script>
<script>

var $
</script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
        $ = layui.$
            , form = layui.form;
        var editor;
        $.post('{:url("getFileBody")}',{cache_key:"{$cache_key}"}, function (res) {
            $("#html").text(res.data.data);
            $("#fileName").text(res.data.filename);
            editor = ace.edit("html");
            editor.setTheme("ace/theme/monokai");
            editor.setFontSize(16);
            editor.getSession().setMode("ace/mode/" + res.data.ext);
        });

        // 事件
        var active = {
            back: function () {
                parent.layer.closeAll();
            },
            save: function () {
                var html = editor.getValue();
                $.post('{:url("saveFileBody")}',{cache_key:"{$cache_key}",html:html}, function (res) {
                    if(res.code == 1) {
                        showSuccessMsg("已保存")
                    } else {
                        showErrMsg(res.msg)
                    }
                });
            }
        };

        $("body").on('click','*[ht-event]',function () {
            var type = $(this).attr('ht-event');
            active[type] ? active[type].call(this) : '';
        });

        window.active = active;
    })
</script>

</body>
</html>